package com.cyandpos.pad.report.reportModel;


import android.text.TextUtils;

import com.cyandpos.pad.common.commondata.BaseResponse;
import com.cyandpos.pad.common.netmanager.PosHttpManager;
import com.cyandpos.pad.http.OkHttpUtils;
import com.cyandpos.pad.posdata.ClassNewspaperAndDaily;
import com.cyandpos.pad.posdata.Payment;
import com.google.gson.JsonObject;

import java.util.ArrayList;
import java.util.List;



public class ReportModel implements IReportModel {


    //交易次数，交易金额，退货次数，退货金额
    private int sumTradeNumber, sumTradeMoney, sumRefundNumber, sumRefundMoney;
    //收款方式集合
    private List<Payment> paymentList = new ArrayList<>();

    private String retCode;

    @Override
    public void doReportHttp(int skyid, final ReportDoModelListener listener) {
        PosHttpManager.ReportExecute(skyid, new OkHttpUtils.ResultCallback() {
            @Override
            public void onSuccess(JsonObject response) {
                BaseResponse<ClassNewspaperAndDaily> baseResponse = BaseResponse.fromJson(response.toString(),ClassNewspaperAndDaily.class);
                if(baseResponse.getCode().equals("0")){
                    try {
                        if (baseResponse.getData()==null)
                            listener.ReportDoModelFailed("暂无数据");
                        else
                        listener.ReportDoModelSuccess(baseResponse.getData());
                    }catch (Exception e){
                        listener.ReportDoModelFailed(baseResponse.getCode() + baseResponse.getMsg() + e.getMessage().toString());
                    }
                }else{
                    if (TextUtils.isEmpty(baseResponse.getTips())){
                        listener.ReportDoModelFailed(baseResponse.getMsg());
                    }else {
                        listener.ReportDoModelFailed(baseResponse.getTips());

                    }
                }
            }


            @Override
            public void onFailure(String msg) {
                listener.ReportDoModelFailed(msg);
            }
        });

    }
    public interface ReportDoModelListener {

        void ReportDoModelSuccess(ClassNewspaperAndDaily daily);

        void ReportDoModelFailed(String errorMsg);
    }





}
